import Item from './index'

function createDiscount(itemData){
  // 代理模式做折扣显示
  return new Proxy(itemData,{
    get: function(target, key, receiver){
      if (key === 'name') {
        return `${target[key]} [折扣]`
      }
      if (key === 'price') {
        return target[key] * 0.8
      }
    }
  })
}

const createItem = (list, itemData) => {
    /* 处理折扣的商品 */
    if (itemData.discount) {
      itemData = createDiscount(itemData)
    }
  return new Item(list, itemData)
}

export default createItem 